$(document).ready(function() {

/**********************************************************************************************************************************************************/
/************************** slider jquery bigins ----- if javascript not enable web page dos not running **************************************************/
/**********************************************************************************************************************************************************/

	var boxwidth = $('.wrap').width();	//getting the wrapper class width
	var screenwidth = $(window).width();
	var maxmaxnum = 8;		//number of slides(forms) on the page
	var currentwindow = 1;	//initial silde number
	
	/*gets the difference bitween screen size and the wrapper size for positioning
	 * the UI elements correctly*/
	var defbox = screenwidth / 2 - boxwidth / 2;

	//positioning the UI elements 
	if(defbox>0)
	{
		$('#box1').css('left',defbox+'px').show();
		$('.headcontent').css('left',defbox+'px');
		$('#vsb1').css('background-color', '#FFFFFF');
	}
	else
	{
		screenwidth = boxwidth+16;
		$('#box1').css('left','8px').show();
		$('.headcontent').css('left','8px');
		$('#vsb1').css('background-color', '#FFFFFF');
	}
	
	
	// positioning the form on screen center when loads (with a simple animation)
	$('html, body').animate({scrollTop: $("#box1").offset().top}, 1000);

//######################################################################################################################	
	//handling window resize events
	$(window).resize(function() {
		  var leftsize = $(window).width() /2 -boxwidth / 2;
		  
		  screenres = leftsize;
		  placementslider();
		  
		  
		  if(leftsize>0)
		  {
			screenwidth = $(window).width();
			$('#box'+currentwindow).css('left',leftsize+'px');
			$('.headcontent').css('left',leftsize+'px');
		  }
		  else
		  {
			screenwidth = boxwidth+16;
			$('#box'+currentwindow).css('left','8px');
			$('.headcontent').css('left','8px');
		  }
		  
	});
	
//#########################################################################################################
	//this function handles the form navigation 'next' buttons click events
	$('a.next').click(function(){
		
		//fades out and fades in the slider key box, when form slide event occur
		$('#abcd').delay(3).fadeOut();
		$('#abcd').delay(5).fadeIn();
		
		//get the 'rel' value of currently clicked form submit button to identify the form id
		var boxrel = parseInt($(this).attr('rel'));
		
		/*if currently clicked form submit button 'rel' values is less than than the 
		 * maximum slide count, fireup an ajax call to submit the RELEVANT form data*/
		if(maxmaxnum > boxrel){
			//form 01 submit event
			/*****************************************************************************/
			if(boxrel == 1){
				//fire up ajax
				$.ajax({
			        type: "POST",
			        url: baseurl+"insertdata/addprop",
			        dataType: "json",
			        data: $('#dataentryterminal'+boxrel).serialize(),
			        cache:false,
			        success: 
			          function(data){
			        	
				        	if(data.validation_result == 'passed'){
				        		
				        		//we hide the submit button to avoid duplications
				        		$('#form01_submit_button').hide();
				        		
				        		/*since the form has submitted sucessfully, its time to load
				        		 * next form on the line.*/
								$('#box'+boxrel).animate({'left': screenwidth+'px'},'slow');
								var nextboxrel = boxrel+1;
								$('#box'+nextboxrel).show();
								$('#box'+nextboxrel).animate({'left':screenwidth / 2 - boxwidth / 2 +'px'},'slow',"linear", function() {
								
									$('#box'+boxrel).hide();
									
								});
								
											/*updates the slider key box colors for '8' keys according the slided
											 * panel*/
											var i = 1;
											for(i; i<=8; i++)
											{
												if(i == nextboxrel)
												{
													$('#vsb'+i).css('background-color', '#FFFFFF');
												}
												else
												{
													$('#vsb'+i).css('background-color', '#707070');
												}
											}
											currentwindow++;
							}
				        	
							else
							{
							//Form validation failed. prepping the relevant error messages and fire up a reveal.
							$('#form01_validation_errors').empty();
							$('#form01_validation_errors').append(data.project_type,data.project_name,data.address_street,
																	data.address_suburb, data.address_district, data.datelaunched,
																	data.introducer, data.competitor, data.project_area_situation,
																	data.howmanyprolandsinthearea, data.closestprospectivelands);
							$('#form01_validation_modal').reveal();
							}
				        }
				});
			}
			
			//form 02 submit event
			/*****************************************************************************/
			else if(boxrel == 2){
				
				//fire up ajax
				$.ajax({
			        type: "POST",
			        url: baseurl+"insertdata/addprop",
			        dataType: "json",
			        data: $('#dataentryterminal'+boxrel).serialize(),
			        cache:false,
			        success: 
			          function(data){
			        	
				        	console.log
				        }
				});
			}
			
			
			//form 03 submit event
			/*****************************************************************************/
			else if(boxrel == 3){}
			
			
			//form 04 submit event
			/*****************************************************************************/
			else if(boxrel == 4){}
			
			
			//form 05 submit event
			/*****************************************************************************/
			else if(boxrel == 5){}
			
			
			//form 06 submit event
			/*****************************************************************************/
			else if(boxrel == 6){}
			
			
			//form 07 submit event
			/*****************************************************************************/
			else if(boxrel == 7){}
			
			
		}
		
		/*
		if maximum slide count is less than or equal to currently clicked form submit button's
		'rel' value, it means user submitting the last form (form 8) and there is no need to slide forms
		further.
		*/
		
		else
		{
			
		}
		
		
		return false;
		
	});
	
//###############################################################################################################################
	//click previous

	$('a.pre').click(function(){
	
		$('#abcd').delay(3).fadeOut();
		$('#abcd').delay(5).fadeIn();
		$('#debug').empty();
		var boxrel = parseInt($(this).attr('rel'));
		
		
		
		//ajax form validation
			
		$.post(baseurl+'insertdata/addprop',$('#dataentryterminal'+boxrel).serialize(), function(data){
			
			//replace field is required
	
			data = data.replace(/field is required/g,"cannot be blank");
			
			if(data=='true')
			{
				$('#box'+boxrel).animate({'left': '-960px'},'slow');
			
			
				var nextboxrel = boxrel-1;
				$('#box'+nextboxrel).show();
				
				
				$('#box'+nextboxrel).animate({'left':screenwidth / 2 - boxwidth / 2 +'px'},'slow',"linear", function() {
					
					$('#box'+boxrel).hide();
						
				});
				
				
				
				//vertical slider colour change
				for(i=1; i<=8; i++)
				{
					if(i==nextboxrel)
					{
						$('#vsb'+i).css('background-color', '#FFFFFF');
					}
					else
					{
						$('#vsb'+i).css('background-color', '#707070');
					}
				}
				
				currentwindow--;
			}
			else
			{
				$('#debug').append(data);
				$('#myModal').reveal({
				     animation: 'fadeAndPop',                   //fade, fadeAndPop, none
				     animationspeed: 300,                       //how fast animtions are
				     closeonbackgroundclick: false,              //if you click background will modal close?
				     dismissmodalclass: 'close-reveal-modal'    //the class of a button or element that will close an open modal
				});
				$("#close-reveal-modal").click(function(){
					$('#debug').empty();
				});
			}
		});
		
		
		
		return false;
	});


/**********************************************************************************************************************************************************/
/**************************************************************** slider ends *****************************************************************************/
/**********************************************************************************************************************************************************/


/**********************************************************************************************************************************************************/
/**************************************************************** virtical slider begins ******************************************************************/
/**********************************************************************************************************************************************************/

	// tab positioning
	
	var screenres =  $(window).width() /2 -boxwidth / 2;
	placementslider();
	
	function placementslider()
	{
		if(screenres<=0)
		{
			leftleszero = boxwidth +11;
			boxleftcorner = 8;
			$('#abcd').css('left',leftleszero+'px');
		}
		else
		{
			leftgrezero = screenres + boxwidth +11;
			boxleftcorner = screenres+8;
			$('#abcd').css('left',leftgrezero+'px');
		}
	}

	//change tab colour

	$('.vsbclass').click(function(){
	
		$('#abcd').delay(3).fadeOut();
		$ ('#abcd').delay(5).fadeIn();
		
		
		var vsclickno  = parseInt($(this).attr('rel'));
		
		
		if(vsclickno != currentwindow)
		{
		
			for(i=1; i<=8; i++)
			{
			
				if(i==vsclickno)
				{
					$('#vsb'+i).css('background-color', '#FFFFFF');
				}
				else
				{
					$('#vsb'+i).css('background-color', '#707070');
				}
			}
			
			//set window
		
			if(currentwindow>vsclickno)
			{
				//hide current window left
				$('#box'+currentwindow).animate({'left': '-960px'},'slow');
				
				
				//req ----------- current left shift
				for(i = currentwindow-1; i>vsclickno; i--)
				{
					$('#box'+i).animate({'left': '-960px'},'slow');
				}
				
				
				
				//fix req window screen
				$('#box'+vsclickno).show();
				$('#box'+vsclickno).animate({'left':boxleftcorner+'px'},'slow',"linear", function() {
				
					$('#box'+currentwindow).hide();
					
					//set current window variable
					currentwindow = vsclickno;
					
				});
				

				
			}
			else
			{
				// hide cuurrent window right
				$('#box'+currentwindow).animate({'left': screenwidth+'px'},'slow');
				
				
				// req ---------- current right shift
				for(i=currentwindow+1; i<vsclickno; i++)
				{
				
					$('#box'+i).animate({'left': screenwidth+'px'},'slow');
				
				}
				
				
				// fix req window screen
				$('#box'+vsclickno).show();
				$('#box'+vsclickno).animate({'left':boxleftcorner+'px'},'slow',"linear", function() {
				
					$('#box'+currentwindow).hide();
					
					//set current window variable
					currentwindow = vsclickno;
					
				});
			
			}
		
		}
	
		return false;
	});
/**********************************************************************************************************************************************************/
/**************************************************************** virtical slider ends*******************************************************************/
/**********************************************************************************************************************************************************/


/**********************************************************************************************************************************************************/
/**************************************************************** form jquery bigins **********************************************************************/
/**********************************************************************************************************************************************************/

//Form 01 functionalities 
//##########################################################################################################################################	
	//this function handles the 'company_name' listbox value change event
	$('#form01_company_selector').change(function(e){
		e.preventDefault();
		if($(this).val() == 'add'){
				
			//clear the input fields before revel fire
			$("input[name='company_name'], input[name='company_display_name']," +
					"textarea[name='company_address'], input[name='company_tp'], input[name='company_email']").attr('value','');
			
			//hide the waiting animation before revel fired up
			$("#add_newcompany_waiter").hide();
			
			//here we hide the 'add company' error notifications before the revel fire
			$('#company_name_error, #company_displayname_error, #company_address_error, #company_tp_error, #company_email_error').hide();
			
			$('#addCompanyModal').reveal();
		}
	});
	

//###########################################################################################################################################	
	//this function select the default option if new company add window closed BY USER
	$('#close_add_new_company-reveal-modal').bind('click', function() {
		$("select[name='form01_company_selector'] option[value='']").attr("selected", true);
		});	


//###########################################################################################################################################	
	//this function handles the submit button click event of new company add window
	$('#company_add').live('click', function() {
		
		//fire up ajax
		$.ajax({
	        type: "POST",
	        url: baseurl+"insertdata/addpropcompany",
	        dataType: "json",
	        data: $('#addCompanyForm').serialize(),
	        cache:false,
	        success: 
	          function(data){
	        	//got a response, hiding the loading animation
	        	$("#add_newcompany_waiter").hide();
	        	/******************************************/
	        	if(data.company_name){
	        		$("#company_name_error").show();
	        		$("#company_name_error").qtip({
	        			content: data.company_name,
	        			position: {
	        				my: 'bottom right',
	        				at: 'top left',
	        				target: $('#company_name_error')
	        			}
	        		});
	        		
	        		}
	        	
	        	else{
	        		$("#company_name_error").hide();
	        	}
	        	
	        	/*******************************************/
	        	if(data.company_display_name){
	        		$("#company_displayname_error").show();
	        		$("#company_displayname_error").qtip({
	        			content: data.company_display_name,
	        			position: {
	        				my: 'bottom right',
	        				at: 'top left',
	        				target: $('#company_displayname_error')
	        			}
	        		});
	        		
	        	}
	        	
	        	else{
	        		$("#company_displayname_error").hide();

	        	}
	        	
	        	/*******************************************************/
	        	if(data.company_address){
	        		$("#company_address_error").show();
	        		$("#company_address_error").qtip({
	        			content: data.company_address,
	        			position: {
	        				my: 'bottom right',
	        				at: 'top left',
	        				target: $('#company_address_error')
	        			}
	        		});
	        	}
	        	
	        	else{
	        		$("#company_address_error").hide();

	        	}
	        	
	        	/***********************************************************/
	        	if(data.company_tp){
	        		$("#company_tp_error").show();
	        		$("#company_tp_error").qtip({
	        			content: data.company_tp,
	        			position: {
	        				my: 'bottom right',
	        				at: 'top left',
	        				target: $('#company_tp_error')
	        			}
	        		});
	        	}
	        	
	        	else{
	        		$("#company_tp_error").hide();

	        	}
	        	
	        	/*************************************************************/
	        	if(data.company_email){
	        		$("#company_email_error").show();
	        		$("#company_email_error").qtip({
	        			content: data.company_email,
	        			position: {
	        				my: 'bottom right',
	        				at: 'top left',
	        				target: $('#company_email_error')
	        			}
	        		});
	        		
	        	}
	        	
	        	else{
	        		$("#company_email_error").hide();
	        	}
	        	
	        	/***************************************************************/
	        	if(data.new_company_id){
	        		$('#form01_company_selector').find('[value="add"]').remove();
	        		$('#form01_company_selector').append('<option selected value="'+data.new_company_id+'">'+data.new_company_display_name+'</option>'
	        												+'<option value="add">Add new</option') ;
	        		$("#close-reveal-modal").trigger("click");
	        	}
	          }
	        
	        });
		
		return false;
	});
	
//################################################################################################################################################################	
	//click abc
	$("#abc").click(function(){
		$('#debug2').empty();
		$("#ownername").val('1');
		return false;
	});
// Datepicker
	
	$("#sec1datelaunched").datepicker();


//#############################################################################################	
	//form 2 jquery

	//add towns
	var townvar = 1;
	var numberoftowns = 1;
	$('a.addtown').click(function (){
		
		if(numberoftowns<5)
		{
			townrowadd(townvar);
			$('#towngrid').append(towntext);
			townvar++;
			numberoftowns++;
		}
		return false;					 
	});
	
	//remove town
	
	$('.remtown').live('click', function() {
	
		var removetown = parseInt($(this).attr('rel'));
		$('#townadd'+removetown).remove();
		numberoftowns--;
		return false;
	});
	
	
	//add road
	var roadui = 1;
	$('a.addroad').click(function (){
			var addroad = parseInt($(this).attr('rel'));
			roadrowadd(addroad,roadui);
			$('#roadgrid0').append(towntext);

			roadui++;
		return false;					 
	});
	
	//add live roads
	
	$('a.addroad').live('click',function (){
		
			var addroad = parseInt($(this).attr('rel'));
			roadrowadd(addroad,roadui);
			$('#roadgrid'+addroad).append(towntext);
		
			roadui++;
		return false;
		
	});
	
	
	//remove town
	
	$('a.remroad').live('click', function(){
		var remroad = parseInt($(this).attr('rel'));
		$('#roadadd'+remroad).remove();
		
		return false;
	});
	
	
	//add busroot and bus numbers
	
	var bustourno = 1;
	var busroutno = 2;
	
	$('a.addbusroot').click(function() {
	
		addbusrootno(bustourno, busroutno);
		
		$('#rootdiscriptiongrid').append(addtransporttext);
		
		bustourno++;
		busroutno++;
		return false;
	});
	
	//remove busroot and bus numbers
	
	$('a.removebusroute').live('click', function(){
	
	$('#busroute'+$(this).attr('rel')).remove();
	return false;
	});
	
	//add bus numbers
	
	$('a.addbusrootnumbers').click(function(){
		
		if($('.bustournumbers').length<9)
		{

			addbusno = "<div style='float:left; width:75px' class='bustournumbers' id='livebusno"+busroutno+"'>";
			addbusno = addbusno +"<input name='bustour_number[0][]' type='text' size='5' style='width:60px;' />";
			addbusno = addbusno +"<a href='#' style='text-decoration:none;' class='rembusrootnumbers' rel='"+busroutno+"'>&times;</a>";
			addbusno = addbusno +"</div>";
			$('#bustournumber').append(addbusno);
			
			busroutno++;
		}

		return false;
	});
	
	//add live buse route numbers
	
	$('a.addbusrootnumbers').live('click', function() {
		if($('.bustournumber'+$(this).attr('rel')).length<9)
		{
		
			addbusno = "<div style='float:left; width:75px' class='bustournumber"+$(this).attr('rel')+"' id='livebusno"+busroutno+"'>";
			addbusno = addbusno +"<input name='bustour_number["+$(this).attr('rel')+"][]' type='text' size='5' style='width:60px;' />";
			addbusno = addbusno +"<a href='#' style=' text-decoration:none;' class='rembusrootnumbers' rel='"+busroutno+"'>&times;</a>";
			addbusno = addbusno +"</div>";
			$('#bustournumber'+$(this).attr('rel')).append(addbusno);
		
		}
	return false;
	});
	
	//remove bus number
	
	$('a.rembusrootnumbers').live('click', function(){
		
		
		$('#livebusno'+$(this).attr('rel')).remove();
		
		return false;
	});
	
	
	//add railway stations
	
	
	//autocomplete railway
	
	
	var railway = ["ABANPOLA", "AGPOPURA", "AHANGAMA", "AKURALA", "ALAWWA", "ALAWWATUPIYIYA", "ALUTHGAMA", "AMBALANGODA", "AMBEPUSSA", "AMBEWELA", "ANAVILUNDAWA", "ANGULANA", "ANU.NEW TOWN", "ANURA'PURA", "ARACHIKATTUWA", "AUNGALLA", "AVISSAWELLA", "AWUKANA", "BADULLA", "BALANA", "BALAPITIYA", "BAMBALAPITIYA", "BANDARAWELA", "BANGADENIYA", "BASE LINE", "BATICALOA", "BATTULUOYA", "BATUWATTA", "BEMMULLA", "BENTOTA", "BERUWALA", "BOLAWATTA", "BOOSHA", "BORALESSA", "BOTALE", "BUJJOMUWA", "BULUGAHAGODA", "CHILAW", "CHINA BAY", "COTTA ROAD", "DARALUWA", "DEHIWAL", "DEMATAGODA", "DEMODARA", "DEVAPURAM", "DIYATALAWA", "DODANDUWA", "EGODA UYANA", "ELLA", "ENDERAMULLA", "ERATTAPRIYAKULAM", "ERAVUR", "FORT", "GAL OYA", "GALABADA", "GALGAMUWA", "GALLE", "GALLELLA", "GAMPAHA", "GAMPOLA", "GANEGODA", "GANEMULLA", "GANEWATTA", "GANGODA", "GELIOYA", "GINTOTATA", "GIRAMBE", "GODAGAMA", "GREAT WESTERN", "HABARADUWA", "HABARANA", "HALI ELA", "HAPUTALE", "HATARESKOTUWA", "HATTON", "HEEL OYA", "HENDENIYAP GODA", "HETTIMULLA", "HIKKADUWA", "HINRAKGODA", "HIRIYALA", "HOMA HOS ROAD", "HOMAGAMA", "HORAPE", "HORIWILA", "HUNUPITIYA", "IDAL GASHINNA", "IHALA WATAWALA", "IHALAKOTTE", "INDURUWA", "INGURUOYA", "JA ELA", "JAYANTIPURAM", "KADADASI NAGAR", "KADIGAMUWA", "KADUGANNAWA", "KAHAWE", "KAKKAPALLIA", "KALAWEWA", "KALKUDAH", "KALU NORTH", "KALU SOUTH", "KAMBURUGGAMUWA", "KANDANA", "KANDEGODA", "KANDY", "KANTALE", "KAPUWATTA", "KATALUWA", "KATTUWA", "KATUGASTOOTA", "KATUGODA", "KATUKURURNDA", "KATUNAYAKA", "KEENAWALA", "KEKIRAWA", "KELANIYA", "KINIGAMA", "KIRULPONE", "KITAL ELLA", "KOGGALA", "KOICHCHIKADE", "KOLPETTI", "KOMPANNAVIDIYA", "KON WEWA", "KORALAWEELA", "KOSGAMA", "KOSGODA", "KOSHINNA", "KOTAGALA", "KOTTAWA", "KUDAHAKAPALA", "KUDAWEW", "KUMARAKANDA", "KUMBALGAMA", "KURANA", "KURUNEGALA", "LAKSHA UYANA", "LIYAAGE MULLA", "LUNAWA", "LUNUWILA", "MADAMPAGAMA", "MADAMPPE", "MADURANKULIYA", "MAGALEGODA", "MAGGONA", "MAHA INDURUWA", "MAHARAGAMA", "MAHAYYAWA", "MAHO", "MALAPALLA", "MANAMPITIYA", "MANGALAELIYA", "MANUWANGAMA", "MARADANA", "MATALE", "MATARA", "MEDAGAMA", "MEDAVACHCHI", "MEEGODA", "MIDIGAMA", "MIHIN JUNCTION", "MINNERIYA", "MIRIGAMA", "MIRISSA", "MOLLIPOTANA", "MORAGOLLAGAMA", "MORATUWA", "MOUNT LAVINIA", "MUNDAL", "MUTTUGALA", "NAGOLLAGAMA", "NAILIYA", "NANU OYA", "NARAHENPITA", "NATHTHANDIYA", "NAVALAPITIYA", "NAWINNA", "NEEGAMA", "NEGOMBO", "NELUMPOKUNA", "NUGEGODA", "OHIYA", "PADUKKA", "PALAVI", "PALLEWELA", "PALUGASWEWA", "PANADURA", "PANAGODA", "PANALIYA", "PANNIPITIYA", "PARAKUMPURA", "PARASANGAHWEWA", "PATANPAHA", "PATEGAMGODA", "PATTIPOA", "PAYA NORTH", "PAYA SOUTH", "PERADENIA", "PERALANDA", "PERKUM UYANA", "PILADUWA", "PILIMATALAWA", "PINNAWALA", "PINWATTA", "PIYADIGAMA", "PIYAGAMA", "POLATHU MODAERA", "POLGAHGAWELA", "POLONNARUWA", "POONANI", "POONEWA", "POTUHERA", "PULICHCHAKULAMA", "PUTTALAM", "PUWAKPITIYA", "RADELLA", "RAGAMA", "RAMBUKKANA", "RANAMUKGAMA", "RANDENIGAMA", "RATGAMA", "RATMALANA", "RICHMAND HILL", "ROZELLA", "SALIYAPURA", "SARASAVI UYANA", "SAWARANA", "SECARATARIAT HOALT", "SEEDUWA", "SEENIGAMA", "SENARATHGAMA", "SIYABALANGAMUWA", "SRIWASTIPURA", "TALAWA", "TALAWAKELE", "TALAWATTEGEDARA", "TALPE", "TAMBILIGALA", "TAMBUTTEGAMA", "TANBALAGAMUWA", "TELWATTA", "TILADIYA", "TIMBIRIYAGEDARA", "TISMALPOLA", "TRAIN HOLT", "TRINCO", "TUDEELLA", "TUMMODARA", "UDAHAMULLA", "UDATALAWINNA", "UDATTAWELA", "UDUWARA", "UKUWELA", "ULAPANE", "UNAWATUNA", "VALACHCHENNAI", "VAUNIA", "VEYANGODA", "WADDUWA", "WAGGA", "WAIKKALA", "WALAHAPITIYA", "WALAKUMBURA", "WALGAMA", "WALPOLA", "WANAWASALA", "WANDURAWA", "WATAGODA", "WATAREKA PLATFORM", "WATAWALA", "WATTEGAMA", "WELIGAMA", "WELIKANDA", "WELLAWA", "WELLAWATTA", "WIJAYARAJADAHANA", "WILWATTA", "YAGODA", "YATAGAMA", "YATHTHALGODA"];
	
	
	
	//railway auto complete
	
	$( ".station_name" ).autocomplete({
			source: railway
	});
	
	
	//live raiway auto complete
	
	$('.station_name').live('keyup', function(){
		$(this).autocomplete({ source : railway });
	});

	
	//add railway row
	
	var railwaygridno = 2;
	
	$('a.addrailway').click(function() {
	
		railwaygridguiadd(railwaygridno);
		$("#railwaygrid").append(railwaytext);
		railwaygridno++;
		return false;
	});
	
	
	//remove railway row
	$('a.removerailway').live('click', function(){
	
		$('#railwayrow'+$(this).attr('rel')).remove();
		return false;
	});
	
	
	// remove (bank hospital school hospital)
		
	function removeRecords(linkname, divname){
		$('.'+linkname).live('click', function(){
			a = divname;
			a = a+$(this).attr('rel');
			$('#'+a).remove();
			return false;
		});
		
	}	
	
	
	//add bank
	
	var bankvar = 2;
	
	$('a.addbank').click(function (){	
		bankdiv = "<div class='fac_row' id='divbank"+bankvar+"'>";
		bankdiv = bankdiv +"<div class='fac_cell'><input id='nameof_bank[]' name='nameof_bank"+bankvar+"' type='text' /></div>";
		bankdiv = bankdiv +"<div class='fac_cell'><input id='distence_bank[]' name='distence_bank"+bankvar+"' type='text' /></div>";
		bankdiv = bankdiv +"<div class='fac_cell2'><a href='#' class='rembank' rel='"+bankvar+"'>Remove</a></div>";
		bankdiv = bankdiv +"</div>";
		$('#bankrecordadd').append(bankdiv);
		bankvar++;
		return false;
	});
	
	//remove bank
	removeRecords('rembank', 'divbank');
	
	//add supermarket
	
	var supvar = 2;
	
	$('a.addsup').click(function (){
		supdiv = "<div class='fac_row' id='divsuper"+supvar+"'>";
		supdiv = supdiv +"<div class='fac_cell'><input name='txt_supname[]' type='text' /></div>";
		supdiv = supdiv +"<div class='fac_cell'><input name='txt_supdistence[]' type='text' /></div>";
		supdiv = supdiv +"<div class='fac_cell2'><a href='#' class='remsup' rel='"+supvar+"'>Remove</a></div>";
		supdiv = supdiv +"</div>";
		$('#supermarketadd').append(supdiv);
		supvar++;
		return false;
	});
	
	//remove supermarket
	
	removeRecords('remsup', 'divsuper');
	
	
	//add hospital

	var hosvar = 2;
	
	$('a.addhos').click(function (){
		hosdiv = "<div class='fac_row' id='divhoser"+hosvar+"'>";
		hosdiv = hosdiv +"<div class='fac_cell'><input name='txt_hosname[]' type='text' /></div>";
		hosdiv = hosdiv +"<div class='fac_cell'><input name='txt_hosdistence[]' type='text' /></div>";
		hosdiv = hosdiv +"<div class='fac_cell2'><a href='#' class='remhos' rel='"+hosvar+"'>Remove</a></div>";
		hosdiv = hosdiv +"</div>";
		$('#hospitaladd').append(hosdiv);
		hosvar++;
		return false;
	});
	
	//remove hospital
	
	removeRecords('remhos', 'divhoser');
	
	
	//add school
	
	
	var schvar = 2;
	
	
	$('a.addsch').click(function (){
		schdiv = "<div class='fac_row' id='divscher"+schvar+"'>";
		schdiv = schdiv +"<div class='fac_cell'><input name='txt_schname[]' type='text' /></div>";
		schdiv = schdiv +"<div class='fac_cell'><input name='txt_schdistence[]' type='text' /></div>";
		schdiv = schdiv +"<div class='fac_cell2'><a href='#' class='remsch' rel='"+schvar+"'>Remove</a></div>";
		schdiv = schdiv +"</div>";
		$('#schooladd').append(schdiv);
		schvar++;
		return false;
	});
	
	//remove school

	removeRecords('remsch', 'divscher');
	
	
	
	//form 3 stuf
	
	
	
	// add new Existing Projects
	var expro = 1;
	$('a.addexistingproject').click(function (){
	
	
		exproject = "<div id='exproject"+expro+"'><br/><br/>";
		exproject = exproject+"<div class='fac_row'>";
		exproject = exproject+"<div class='fac_cell'>Project Owner</div>";
		exproject = exproject+"<div class='fac_cell'><select name='form03_company_selector[]' id='form03_company_selector"+expro+"'>"+form03_company_selector_content+"</select></div>";
		exproject = exproject+"<div class='fac_cell2'><a href='#' class='remexistingproject' rel='"+expro+"'>Remove</a></div>";
		exproject = exproject+"</div>";
		exproject = exproject+"<div class='fac_row'>";
		exproject = exproject+"<div class='fac_cell'>No. of blocks</div>";
		exproject = exproject+"<div class='fac_cell'><input name='noofblocks[]' id='noofblocks"+expro+"'  type='text' size='20' /></div>";
		exproject = exproject+"<div class='fac_cell'>Extent </div>";
		exproject = exproject+"<div class='fac_cell'><input name='extent[]' id='extent"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"</div>";
		exproject = exproject+"<div class='fac_row'>";
		exproject = exproject+"<div class='fac_cell'>No. of blocks Sold</div>";
		exproject = exproject+"<div class='fac_cell'><input name='noofblockssold[]' id='noofblockssold"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"<div class='fac_cell'>Average Block size</div>";
		exproject = exproject+"<div class='fac_cell'><input name='averageblocksize[]' id='averageblocksize"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"</div>";
		exproject = exproject+"<div class='fac_row'>";
		exproject = exproject+"<div class='fac_cell'>No. of available Blocks</div>";
		exproject = exproject+"<div class='fac_cell'><input name='noofavalibleblocks[]' id='noofavalibleblocks"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"<div class='fac_cell'></div>";
		exproject = exproject+"<div class='fac_cell'></div>";
		exproject = exproject+"</div>";
		exproject = exproject+"<div class='fac_row'>Price</div>";
		exproject = exproject+"<div class='fac_row'>";
		exproject = exproject+"<div class='fac_cell'>Facing main road</div>";
		exproject = exproject+"<div class='fac_cell'><input name='facingmainroad[]' id='facingmainroad"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"<div class='fac_cell'>Second row</div>";
		exproject = exproject+"<div class='fac_cell'><input name='secondrow[]' id='secondrow"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"</div>";
		exproject = exproject+"<div class='fac_row'>";
		exproject = exproject+"<div class='fac_cell'>Average</div>";
		exproject = exproject+"<div class='fac_cell'><input name='average[]' id='average"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"<div class='fac_cell'>Minimum</div>";
		exproject = exproject+"<div class='fac_cell'><input name='minimum[]' id='minimum"+expro+"' type='text' size='20' /></div>";
		exproject = exproject+"</div>";
		exproject = exproject+"<div class='fac_row'>";
		exproject = exproject+"<div class='fac_cell3'>Facing / Bordering an attraction  &nbsp;</div>";
		exproject = exproject+"<div class='fac_cell3'><select name='facingbordering[]' id='facingbordering"+expro+"' id='facingbordering'><option value='option 1'>option 1</option><option value='option 2'>option 2</option></select></div>";
		exproject = exproject+"</div>";
		exproject = exproject+"</div>";
		
		$('#excistingprojectgrid').append(exproject);
		
		expro++;
		
		return false;
	});
	
	//remove Existing Projects
	
	$('a.remexistingproject').live('click', function(){
		
		$('#exproject'+$(this).attr('rel')).remove();
		
		return false;
	});
	
	
	//form 4 stuf
	
	
	//Entrance to land
	
	
	var preference = 2;
	
	
	$('a.freferenceadd').click(function(){
	
		preferencetext = "<div id='preference"+preference+"'><br/><br/>";
		preferencetext = preferencetext+"<div class='landtop_row4'>";
		preferencetext = preferencetext+"<div class='landtop_cell'></div>";
		preferencetext = preferencetext+"<div class='landtop_cell'><select name='roadwidth[]' id='roadwidth"+preference+"'><option value='wide'>wide</option><option value='narrow'>narrow</option></select></div>";
		preferencetext = preferencetext+"<div class='landtop_cell'><select name='roadtype[]' id='roadtype"+preference+"'><option value='private'>private</option><option value='public'>public</option></select></div>";
		preferencetext = preferencetext+"<div class='landtop_cell'><a href='#' class='freferenceadd' rel='"+preference+"'>Remove</a></div>";
		preferencetext = preferencetext+"</div>";
		preferencetext = preferencetext+"<div class='landtop_row4'>";
		preferencetext = preferencetext+"<div class='landtop_cell'>First Level</div>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Width &nbsp;<input type='text' name='roadfwidth[]' id='roadfwidth"+preference+"' size='9' /></div>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Height &nbsp;<input type='text' name='roadfheight[]' id='roadfheight"+preference+"' size='9' /></div>";
		preferencetext = preferencetext+"</div>";
		preferencetext = preferencetext+"<div class='landtop_row4'>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Second Level</div>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Width &nbsp;<input type='text' name='roadswidth[]' id='roadswidth"+preference+"' size='9' /></div>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Height &nbsp;<input type='text' name='roadsheight[]' id='roadsheight"+preference+"' size='9' /></div>";
		preferencetext = preferencetext+"</div>";
		preferencetext = preferencetext+"<div class='landtop_row4'>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Third Level</div>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Width &nbsp;<input type='text' name='roadtwidth[]' id='roadtwidth"+preference+"' size='9' /></div>";
		preferencetext = preferencetext+"<div class='landtop_cell'>Height &nbsp;<input type='text' name='roadsteight[]' id='roadtheight"+preference+"' size='9' /></div>";
		preferencetext = preferencetext+"</div>";
		preferencetext = preferencetext+"</div>";
		
		$('#preferencegrid').append(preferencetext);
		
		preference++;
		
		return false;
	});
	
	//remove enrance land
	
	
	$('a.freferenceadd').live('click', function(){
		
		$('#preference'+$(this).attr('rel')).remove();
		
		return false;
	});
	
	
	//form 5 
	$("#waterpipedistence").attr("disabled", "disabled"); 
	$("#pipewaterdisconnected").attr("disabled", "disabled"); 
	$("#disconnecter").attr("disabled", "disabled");
	
	//pipe water checkbox event
	$('#pipewater').change(function(){
		
		if ($('#pipewater').is(':checked')) {
			
			$("#waterpipedistence").removeAttr("disabled");
			$("#pipewaterdisconnected").removeAttr("disabled");
		    
		}
		else
		{
			$("#waterpipedistence").attr("disabled", "disabled"); 
			$("#pipewaterdisconnected").attr("disabled", "disabled"); 
		}

	});
	
	
	//is pipe water disconnected
	
		$('#isgwather').change(function(){
		
		if ($('#isgwather').is(':checked')) {
			
			$("#depthwater").removeAttr("disabled");
			$("#depthwatercondition").removeAttr("disabled");
		    
		}
		else
		{
			$("#depthwater").attr("disabled", "disabled"); 
			$("#depthwatercondition").attr("disabled", "disabled"); 
		}

	});
	
	$('#pipewaterdisconnected').change(function(){
		

		if ($('#pipewaterdisconnected').is(':checked')) {
			
			$("#disconnecter").removeAttr("disabled");
		    
		}
		else
		{
			$("#disconnecter").attr("disabled", "disabled"); 
		}

	});
	
	//pc2gi add
	var pc2gi = 2;
	
	
	$('a.pc2gi').click(function(){
		
		pc2gifunction(pc2gi);
		$('#pc2gigrid').append(pc2gitext);
		
		pc2gi++;
		return false;
	});
	
	$('a.rempc2gi').live('click', function(){
	
		$("#pc2girow"+$(this).attr('rel')).remove();
		return false;
	});

});